<?php
class Daliy{

	public function getDaliy($id,$r_date){
		$DB = new DB();
		$sql = "SELECT * FROM daliy 
				WHERE kid_id='$id'
				AND date='$r_date'";
		
		return $DB->fetchRow($sql);
	}
	
	public function addDaliy($kid,$class,$status,$lunch,$siesta,$perform,$r_date){
		$DB = new DB();
		$sql = "INSERT INTO `daliy` VALUES (:id,:date,:kid_id,:class_id,:status,:lunch,:siesta,:perform,:comment)";
		$field = array(':id' => '',
					   ':date' => $r_date,
					   ':kid_id' => $kid,
					   ':class_id' => $class,
					   ':status' => $status,
					   ':lunch' => $lunch,
					   ':siesta' => $siesta,
					   ':perform' => $perform,
					   ':comment' => ''
					   
					  );	
		return $DB->updateDB($sql,$field);			
	}
	
	public function getDaliyById($id){
		$DB = new DB();
		$sql = "SELECT * from course where id='$id'";
		return $DB->fetchRow($sql);
		
	}
	
	public function editDaliy($id,$status,$lunch,$siesta,$perform){
		$DB = new DB();
		$sql = "UPDATE `daliy` set status=?,lunch=?,siesta=?,perform=? where id='$id'";
		$field = array($status,$lunch,$siesta,$perform);
		return $DB->updateDB($sql,$field);	
	}
	
	public function delCourse($id){
		global $db;
		$sql = "delete from `course` where id='$id'";
		return $db->query($sql);		
	}
	
	public function getTDaliyByClass($class_id){
		$DB = new DB();
		$sql = "select count(*) as total from `daliy` where class_id='$class_id' and date='".date("Y-m-d")."'";
	
		return $DB->fetchRow($sql);
	}
	
	public function editCs($class,$lesson,$field,$value){
		$DB = new DB();
		$sql = "UPDATE `cs` set $field=? where lesson = '$lesson' and class_id = '$class'";
		
		$field = array($value);
		return $DB->updateDB($sql,$field);		
	}
}
?>